<?PHP
require_once 'class.sql.php';

abstract class WpEnvironemt extends sqlService {
	//public $sql= null;
	abstract protected function initAllVariables();
	protected $returnHeader = true;
	
	public function printVariable($query)
	{
		echo '<pre>';
		print_r($query);
		echo '</pre>';
	}
	public function doGet($url)
	{
		return $this->doPost($url, null, null);
	}
	
	protected function doEndSession($cookieDirectory)
	{
		unlink($cookieDirectory);
	}
	protected function doCollectCookies($url)
	{
		$ch = curl_init();

		$cookieDirectory = tempnam( dirname(__FILE__) . "/transfer/", 'SM_');
		curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieDirectory );
		curl_setopt($ch, CURLOPT_URL, $url);
		
		if( $this->returnHeader == true)
		{
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_VERBOSE, 1);
			curl_setopt($ch, CURLOPT_HEADER, 1);			
		}
		
		$response = null;
		$response = curl_exec ($ch);
		curl_close ($ch);
		
		return $cookieDirectory;
	}
	
	protected function doPost($url, $data, $cookieDirectory)
	{
		$ch = curl_init();
		if( $this->returnHeader == true)
		{
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_VERBOSE, 1);
			curl_setopt($ch, CURLOPT_HEADER, 1);
			curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)");			
		}
		if( $data != null)
		{
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data) );
			curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieDirectory);
		}
		curl_setopt($ch, CURLOPT_URL,$url);
		
		$response = curl_exec ($ch);
		curl_close ($ch);
		
		return $response;
	}
	
	
	public function __construct()
	{
		parent::__construct();
		//$this->sql= new sqlService();
	}
	
	public function printArray($array)
	{
		echo '<pre>';
		print_r($array);
		echo '</pre>';
	}
	
	public function printException($e) {
		echo "<h3>Caught exception: <font style='color:red'>{$e->getMessage()}</font></h3><hr/>";
	}
};
?>